package cn.sdc.bugKiller.bean;

import java.util.List;

public class BugDealBean {

	//bug id
	private Integer id;
	
	private BugBean bug;
	
	private BugProcessBean currProcess;
	
	private List<BugProcessBean> processList;

	/**
	 * 1 -> 已解决
	 * 2 -> 转发给其他人来修改
	 * 3 -> 未修复
	 * 4 -> 未修复转发给其他人来修改
	 * 5 -> 已承认
	 */
	private Integer result;
	
	private Integer currStatus;
	
	private Integer forward;
	
	private String bugReply;
	
	private Boolean assignerFlg = false;
	
	private Boolean handlerFlg = false;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public BugBean getBug() {
		return bug;
	}

	public void setBug(BugBean bug) {
		this.bug = bug;
	}

	public BugProcessBean getCurrProcess() {
		return currProcess;
	}

	public void setCurrProcess(BugProcessBean currProcess) {
		this.currProcess = currProcess;
	}

	public List<BugProcessBean> getProcessList() {
		return processList;
	}

	public void setProcessList(List<BugProcessBean> processList) {
		this.processList = processList;
	}

	public Integer getResult() {
		return result;
	}

	public void setResult(Integer result) {
		this.result = result;
	}

	public Integer getCurrStatus() {
		return currStatus;
	}

	public void setCurrStatus(Integer currStatus) {
		this.currStatus = currStatus;
	}

	public Integer getForward() {
		return forward;
	}

	public void setForward(Integer forward) {
		this.forward = forward;
	}

	public String getBugReply() {
		return bugReply;
	}

	public void setBugReply(String bugReply) {
		this.bugReply = bugReply;
	}

	public Boolean getAssignerFlg() {
		return assignerFlg;
	}

	public Boolean getHandlerFlg() {
		return handlerFlg;
	}

	public void setAssignerFlg(Boolean assignerFlg) {
		this.assignerFlg = assignerFlg;
	}

	public void setHandlerFlg(Boolean handlerFlg) {
		this.handlerFlg = handlerFlg;
	}

	public Boolean getFixFlg(){
		return handlerFlg&bug.getStatus().equals(BugStatus.STATUS_UNFIX);
	}

	public Boolean getApprovalFlg(){
		return assignerFlg&bug.getStatus().equals(BugStatus.STATUS_APPROVAL);
	}
	
	public Boolean getForceCloseFlg(){
		return assignerFlg&bug.getStatus().equals(BugStatus.STATUS_UNFIX);
	}
	
	public Integer getNextProcessStatus(){
		if(bug==null || bug.getStatus() == null || result == null){
			return null;
		}
		if(BugStatus.STATUS_UNFIX.equals(bug.getStatus()) 
				&& BugDealResult.RESULT_FIX.equals(result)){
			return BugStatus.STATUS_APPROVAL;
		}
		if(BugStatus.STATUS_UNFIX.equals(bug.getStatus()) 
				&& BugDealResult.RESULT_FORCE_CLOSED.equals(result)){
			return BugStatus.STATUS_FORCE_CLOSED;
		}
		if(BugStatus.STATUS_APPROVAL.equals(bug.getStatus()) 
				&& BugDealResult.RESULT_REJECT.equals(result)){
			return BugStatus.STATUS_UNFIX;
		}
		if(BugStatus.STATUS_APPROVAL.equals(bug.getStatus()) 
				&& BugDealResult.RESULT_CLOSED.equals(result)){
			return BugStatus.STATUS_CLOSED;
		}
		return null;
	}
	
	public Integer getNextBugStatus(){
		Integer processStatus = getNextProcessStatus();
		if(processStatus == null){
			return null;
		}
		if(BugStatus.STATUS_FORCE_CLOSED.equals(processStatus)){
			return BugStatus.STATUS_CLOSED;
		}
		if(BugStatus.STATUS_REASSIGN.equals(processStatus)){
			return BugStatus.STATUS_UNFIX;
		}
		return processStatus;
	}

	public BugProcessBean createBlankNextProcess() {
		if(bug==null){
			return null;
		}
		BugProcessBean processBean = null;
		if(BugStatus.STATUS_UNFIX.equals(bug.getStatus()) ){
			processBean = new BugProcessBean();
			processBean.setBug(id);
			processBean.setAssigner(bug.getHandler());
			processBean.setAssignerName(bug.getHandlerName());
			processBean.setStatus(BugStatus.STATUS_UNFIX);
			return processBean;
		}
		if(BugStatus.STATUS_APPROVAL.equals(bug.getStatus()) ){
			processBean = new BugProcessBean();
			processBean.setBug(id);
			processBean.setAssigner(bug.getAssigner());
			processBean.setAssignerName(bug.getAssignerName());
			processBean.setStatus(BugStatus.STATUS_APPROVAL);
			return processBean;
		}
		return processBean;
	}
	
	public BugProcessBean createNextProcess(){
		BugProcessBean processBean = createBlankNextProcess();
		if(processBean != null){
			if(BugStatus.STATUS_UNFIX.equals(bug.getStatus()) ){
				processBean.setHandler(bug.getAssigner());
			}
			if(BugStatus.STATUS_APPROVAL.equals(bug.getStatus())
					&& !BugDealResult.RESULT_CLOSED.equals(result) ){
				processBean.setHandler(bug.getHandler());
			}
			processBean.setBugReply(bugReply);
			processBean.setStatus(getNextProcessStatus());
		}
		return processBean;
	}
	
	public BugProcessBean createForceCloseProcess(){
		BugProcessBean processBean = new BugProcessBean();
		processBean.setBug(id);
		processBean.setAssigner(bug.getAssigner());
		processBean.setBugReply(BugProcessBean.FORCE_CLODE_BUG_REPLY);
		processBean.setStatus(BugStatus.STATUS_FORCE_CLOSED);
		return processBean;
	}
}
